package daniel.k.supportdesigndemo;

import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

public class TextInputLayoutActivity extends AppCompatActivity {

    @ViewInject(R.id.et_mail)
    EditText et_mail;
    @ViewInject(R.id.et_name)
    EditText et_name;

    @ViewInject(R.id.til_mail)
    TextInputLayout til_mail;
    @ViewInject(R.id.til_name)
    TextInputLayout til_name;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text_input_layout);
        ViewUtils.inject(this);
        til_mail= (TextInputLayout) findViewById(R.id.til_mail);
        et_mail=til_mail.getEditText();
        et_mail.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                //开启错误显示
                til_mail.setErrorEnabled(true);
                //设置错误显示
                til_mail.setError("Error hint,你没有权限输入。");
                til_mail.setErrorEnabled(false);

            }
        });
        et_name.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                et_name.setError("这里是EditText设置的Error");
            }
        });
    }
}
